package com.happypets.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.happypets.mail.FaSong;
import com.happypets.model.UserBean;
import com.happypets.servicesImpl.UserServiceImpl;

/**
 * Servlet implementation class SendFindMail
 */
public class SendFindMail extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SendFindMail() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String name = request.getParameter("user");
		
		UserServiceImpl userSer = new UserServiceImpl();
		FaSong fs = new FaSong();
		
		UserBean ub = userSer.getUserBeanByName(name);
		
		String mail = ub.getUserEmail();
		
		fs.sendMail(ub.getUserId(), mail);
		
		response.sendRedirect(request.getContextPath()+"/web/index.jsp");
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
